home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 06 - 1990 / 06.11 Nov 90 / Nov XCMD Code
Encoding:
Text File  |  1990-09-21  |  2.1 KB  |  104 lines  |  [TEXT/nX^n]

  1. /**********************************/
  2. /* File: Sample.c            */
  3. /*                        */
  4. /* A sample XCMD for Hypercard    */
  5. /* 2.0                    */
  6. /*                        */
  7. /* Well-behaved XCMDs for HC2.0    */
  8. /* will respond to the ! and ?    */
  9. /* requests by returning version    */
  10. /* and usage information         */
  11. /* respectively.                */
  12. /*                        */
  13. /* ----------------------------    */
  14. /* ©1990, Donald Koscheka        */
  15. /* All Rights Reserved            */
  16. /**********************************/
  17.  
  18. /*
  19.     Project:
  20.  
  21.         ANSI-A4    -- standard "C" libraries assembled
  22.                     off of register A4
  23.                     
  24.         MacTraps
  25.         Sample2.0.c (contents of listing 1)
  26.  
  27.     Set Project Type:
  28.         Type == XCMD | XFCN
  29.         Name == SimpleXCMD
  30.         id     == 1000
  31.         
  32.     Usage
  33.     
  34.         SimpleXCMD "?"
  35.         SimpleXCMD "!"
  36.         put the result
  37.         
  38.         OR
  39.             
  40.         Put simpleXCMD( "?" )
  41.         Put simpleXCMD( "!" )
  42. */
  43.  
  44. #include    <SetUpA4.h>
  45. #include    <string.h>
  46. #include    <HyperXCMD.h>
  47.  
  48. #ifndef    NIL
  49.     #define NIL    (void *)0L
  50. #endif
  51.  
  52. Handle    strToParam( str )
  53.     char    *str;
  54. /***************************
  55. * Given a pointer to a string,
  56. * copy that string into a handle
  57. * and return the handle.
  58. *
  59. * The input and output strings
  60. * are both null-terminated
  61. *
  62. ***************************/
  63. {
  64.     Handle    outH = NIL;
  65.     long    len    = 0;
  66.     
  67.     len = strlen( str );
  68.     if( len )
  69.         if( outH = NewHandle( len ) )
  70.             BlockMove( str, *outH, len + 1 );
  71.     
  72.     return( outH );
  73. }
  74.  
  75. pascal void main( paramPtr )
  76.     XCmdPtr    paramPtr;
  77. {
  78.     Handle    answer    = NIL;
  79.     char    *str;
  80.     long    len;
  81.     
  82.     paramPtr->returnValue = NIL;
  83.  
  84.     /** The first thing that a well-behaved        **/
  85.     /** HC2.0 XCMD should do is check to see    **/
  86.     /** whether the first (and only) parameter    **/
  87.     /** is the user request for information or    **/
  88.     /** or usage information.  If so, just pass **/
  89.     /** your answer back to the user, otherwise **/
  90.     /** go ahead and perform your xcmd services **/
  91.     
  92.     if (paramPtr->paramCount == 1){
  93.         if ( **(paramPtr->params[0]) == '!' ){
  94.             paramPtr->returnValue = strToParam("Simple XCMD, version 1.0, ©Donald Koscheka, 1990");
  95.             return;
  96.         }
  97.         
  98.         if ( **(paramPtr->params[0]) == '?' ){
  99.             paramPtr->returnValue = strToParam("Simple takes no parameters and does nothing with them.");
  100.             return;
  101.         }
  102.     }
  103. }
  104. Listing 1. SimpleXCMD.c